home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
025a
/
prgmchk.zip
/
PARENCHK.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1991-07-21
|
4KB
|
121 lines
*( PARENCHK.CMD - parentheses checker routine - This routine
compares number of ( vs number of ) per line and prints the line if the
totals don't agree: If the totals are off but the line ends with a +
(Rbase continuation symbol) then the routine skips to the next line
before comparing totals. The routine also checks the sequence of
opening and closing parentheses and flags the location within a line
where the number of closing exceeds the number of opening parentheses.
created 11 July 91; Wm Driskell)
set mess off
set err mess off
set err var verr
set v blnk text = (char(32)), coma text = (char(44))
set v lastchar text = .blnk
set v oddchar = (char(254))
set var plus = (char(43))
set quote = .oddchar *(oddchar=■)
set zero on
set v lineknt int = 0
CLS
WRITE ■Parentheses Checker■
WRITE ■-------------------■
WRITE ■ ■
fillin ifile$ using ■Enter name of file to check: ■
fillin ofile$ using ■Enter name of file for output: ■
out .ofile$
write ■File: ■,.ifile$
write ■ ■
out scr
*( setup counters and constants )
set v rpknt int = 0, lpknt int = 0
set v lp$ text = (char(40))
set v rp$ text = (char(41))
drop cursor c1
drop tab t$$
write ■loading the data...■
create tab T$$ codeline text 100
set delimit=.oddchar
set blank =.oddchar
load■t$$■from■.ifile$■as■ascii
set■blank=.blnk
set delimit=.coma
*( get line and parse for parentheses )
out scr with .ofile$ append
write ■Line #: total left paren and right paren counts■
write ■-----------------------------------------------■
out scr
compute lk as rows from T$$
*( get line and parse for parentheses )
declare c1 cursor for select codeline from t$$
open c1
fetch c1 into a$ ind1
while sqlcode <> 100 then
set v lineknt = (.lineknt + 1)
write ■line■,.lineknt,■of■,.lk at 1 65 reverse
set v a$ = (strim(.a$))
set v vslen = (slen(.a$))
if (a$ not cont .lp$) and (a$ not cont .rp$) then
GOTO skipline
endif
set v l = (sloc(.a$,.lp$))
set v r = (sloc(.a$,.rp$))
set v b$ = .a$
while (.l + .r) > 0 then
IF l > 0 THEN
set v b$ = (sput(.b$,■!■,.l))
set v lpknt = (.lpknt + 1)
ENDIF
IF r > 0 THEN
set v b$ = (sput(.b$,■!■,.r))
set v rpknt = (.rpknt + 1)
ENDIF
IF r < l AND lpknt <= rpknt THEN
out scr with .ofile$ append
WRITE ■==>■, .lineknt, ■**** Too Many Right Parentheses ****■
WRITE .a$
set v c$ = (sfil(■.■,.vslen))
set v c$ = (sput(.c$,■^■,.r))
WRITE .c$
out scr
ENDIF
set v l = (sloc(.b$,.lp$))
set v r = (sloc(.b$,.rp$))
endwhile
LABEL skipline
set v lastchar = (sget(.a$,1,.vslen)) *(check for continuation char)
IF lpknt <> rpknt AND lastchar <> .plus THEN
out scr with .ofile$ append
WRITE ■==>■, .lineknt, ■: ■, .lpknt, .rpknt
WRITE .a$
out scr
ENDIF
fetch c1 into a$ ind1
endwhile
drop cursor c1
out scr with .ofile$ append
WRITE ■ ■
WRITE ■:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::■
WRITE ■ ■
WRITE ■total lines processed: ■,.lineknt
WRITE ■total number of parentheses: left - ■,.lpknt, ■right - ■,.rpknt
WRITE ■ ■
WRITE ■::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::■
WRITE ■ ■
out scr
set quote='
set mess on
set err mess on
clear var blnk,plus,lastchar,oddchar,lineknt,a$,b$,lpknt,rpknt,lp$,rp$,l,r, +
vsloc,vslen,ofile$,ifile$,ind1,lk,verr,coma
return